/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stage;

import java.io.*;

/**
 *
 * @author matteo
 */
public class CreaGridJML {

    public static void main(String args[]) {

        String path = "/home/nacco/uni/stage/griglia.jml";
        try {
            double xi = 500000.0,xf = 800000.0,yi = 5000000.0, yf = 5500000.0, width = 100000.0 ;


            double yii=yi;

            File file = new File(path);

            FileOutputStream fos = new FileOutputStream(file);
            PrintStream out = new PrintStream(fos);
            char virgolette = '"';
            char virgola = ',';

            out.println("<?xml version='1.0' encoding='UTF-8'?>");
            out.print("<JCSDataFile xmlns:gml=");
            out.print(virgolette);
            out.print("http://www.opengis.net/gml");
            out.print(virgolette);
            out.print(" xmlns:xsi=");
            out.print(virgolette);
            out.print("http://www.w3.org/2000/10/XMLSchema-instance");
            out.print(virgolette);
            out.println(" >");
            out.println("<JCSGMLInputTemplate>");
            out.println("<CollectionElement>featureCollection</CollectionElement> ");
            out.println("<FeatureElement>feature</FeatureElement>");
            out.println("<GeometryElement>geometry</GeometryElement>");
            out.println("<ColumnDefinitions>");
            out.println("</ColumnDefinitions>");
            out.println("</JCSGMLInputTemplate>");
            out.println("");
            out.println("<featureCollection>");

            while (yii <= yf) {
                scriviTagIniziali(out);

                out.print("" + xi);

                out.print(virgola);
                out.print("" + yii);

                out.println("");

                out.print("" + xf);

                out.print(virgola);
                out.print("" + yii);

                scriviTagFinali(out);

                yii = yii + width;
            }

            while (xi <= xf) {
                scriviTagIniziali(out);

                out.print("" + xi);

                out.print(virgola);
                out.print("" + yi);

                out.println("");

                out.print("" + xi);

                out.print(virgola);
                out.print("" + yf);

                scriviTagFinali(out);

                xi = xi + width;
            }

            out.println("</featureCollection>");
            out.println("</JCSDataFile>");

        } catch (IOException e) {
            e.printStackTrace();
        }

    }//end main

    public static void scriviTagIniziali(PrintStream out) {
        out.println("<feature>");
        out.println("<geometry>");
        out.println("<gml:LineString>");
        out.println("<gml:coordinates>");
    }

    public static void scriviTagFinali(PrintStream out) {
        out.println("</gml:coordinates>");
        out.println("</gml:LineString>");
        out.println("</geometry>");
        out.println("</feature>");
    }
}//end class

